<template>
	<view>
		<view class="bbox">
			<view :class="['xbox',zindex==index?'active':'']" v-for="(item,index) in title" :key="index"
				@click="change(index)">
				{{item}}
			</view>
		</view>
		<!-- 订单列表 -->

		<view v-if="orderList.length>0">
			<view v-for="(item,index) in orderList" :key="index">
				<my-goods :item="item" :showAddress="true" :showcount="true" :showif="true" :showall="true"></my-goods>
			</view>
		</view>

		<view class="empty-cart" v-else>
			<image src="/static/cart_empty@2x.png" class="empty-img"></image>
			<text class="tip-text">空空如也~</text>
		</view>

		<view style="height: 100rpx;">
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				zindex: 0,
				title: ['全部订单', '待发货', '待收货', '退款/退货'],
				orderList: []
			}
		},
		onLoad(o) {
			if (o.index) {
				this.zindex = o.index
				this.change(this.zindex)
			} else {
				this.zindex = 0
				this.getOrderlist()
			}
		},
		methods: {
			change(index) {
				this.zindex = index
				if (this.zindex == 0) {
					this.getOrderlist()
				} else {
					this.getOrderListChoose(index)
				}

			},
			async getOrderListChoose(index) {
				let res = await uni.$http.post('/getOrderListChoose', {
					goods_state: index
				})
				this.orderList = res.data
			},
			async getOrderlist() {
				let res = await uni.$http.get('/getOrderList')
				this.orderList = res.data
			}

		}
	}
</script>

<style lang="scss" scoped>
	.bbox {
		display: flex;
		margin: 30rpx;
		justify-content: space-between;

		.xbox {
			padding-bottom: 10rpx;
		}

		.active {
			color: #be0101;
			border-bottom: 4rpx solid #be0101;
		}
	}

	.empty-cart {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 150px;

		.empty-img {
			width: 90px;
			height: 90px;
		}

		.tip-text {
			font-size: 12px;
			color: gray;
			margin-top: 15px;
		}
	}
</style>